# makfile configuration
NAME            = control

OBJECTS         = ctrl_freq.o ctrl_station.o ctrl_vol.o ctrl_mem.o

#should be 149, waiting for wsim
CPU             = msp430x149

DEPS	= ../driver/led.o ../driver/frequence.o ../driver/volume.o
DRIVER_DIR	= ../driver/

# Includes necessaire pour les appels systemes
OSDIR		= ../os
RTOSDIR		= $(OSDIR)/OS/
PORTDIR         = $(OSDIR)/Ports/MSP430/F1611/GNU

INCDIRS		= -I$(OSDIR) -I$(PORTDIR) -I$(RTOSDIR)

# default flags for compilation
DEFAULT_FLAGS	= -mmcu=${CPU} $(INCDIRS) -Wall -g

#switch the compiler (for the internal make rules)
CC              = msp430-gcc
# use when building the entire program
CFLAGS          = ${DEFAULT_FLAGS}


.PHONY: all FORCE clean download download-jtag download-bsl dist

#all should be the first target. it's built when make is run without args
all: clean driver ${OBJECTS}

#additional rules for files
${NAME}.elf: driver ${OBJECTS}
	${CC} -mmcu=${CPU} -o $@ ${OBJECTS} ${DEPS}

driver:
	@(cd $(DRIVER_DIR) && $(MAKE));

${NAME}.a43: ${NAME}.elf
	msp430-objcopy -O ihex $^ $@

${NAME}.lst: ${NAME}.elf
	msp430-objdump -dSt $^ >$@

${NAME}.dmp: ${NAME}.elf
	msp430-objdump -d $^ >$@

.s: .c
	${CC} -S $(CFLAGS) $^ >$@

download-jtag: all
	msp430-jtag -e ${NAME}.elf

download-bsl: all
	msp430-bsl -e ${NAME}.elf

clean:
	@(cd $(DRIVER_DIR) && $(MAKE) clean); \
	rm -f ${NAME}.elf ${NAME}.a43 ${NAME}.lst ${OBJECTS} wsim-* *~

#backup archive
dist:
	tar czf LCD.tgz *.c *.h  Makefile

#dummy target as dependecy if something has to be build everytime
FORCE:

#project dependencies
ctrl_freq.o: ../driver/frequence.h


ctrl_vol.o: ../driver/volume.h


.o: ../utils/utils.h .c

